/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Usuario;

import clienteSandraParada.Login;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.ActionMapUIResource;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
/**
 *
 * @author Mario
 */
public class Privilegios extends java.awt.Dialog implements TreeSelectionListener {

    private CheckTreeSelectionModel selectionModel; 
    private int hotspot = new JCheckBox().getPreferredSize().width;
    private service.Usuario usuario;
    
    public Privilegios(java.awt.Frame parent, boolean modal, service.Usuario usuario) {
        super(parent, modal);
        initComponents();
        setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());
        this.usuario = usuario;        
        this.setTitle("Privilegios");        
        this.setLocationRelativeTo(null);
        selectionModel = new CheckTreeSelectionModel(arbolContenedor.getModel()); 
        arbolContenedor.setCellRenderer(new CheckTreeCellRenderer(arbolContenedor.getCellRenderer(), selectionModel)); 
        if(usuario != null){            
            campoNombreActivo.setText(Login.getUser().getNombres()+" "+Login.getUser().getApellidoPaterno()+" "+Login.getUser().getApellidoMaterno());
            campoRutActivo.setText(Login.getUser().getRut());
            campoNombreModificar.setText(usuario.getNombres()+" "+usuario.getApellidoPaterno()+" "+usuario.getApellidoMaterno());
            campoRutModificar.setText(usuario.getRut());
            campoTipoCuenta.setSelectedItem(usuario.getTipoCuenta());
            cargarPrivilegiosUsuario();
        }
        normalizarMensajeria();
        arbolContenedor.addMouseListener(new MouseListener(){

            @Override
            public void mouseClicked(MouseEvent me) {
                mouseClick(me);
            }
            @Override
            public void mousePressed(MouseEvent me) {                
            }
            @Override
            public void mouseReleased(MouseEvent me) {                
            }
            @Override
            public void mouseEntered(MouseEvent me) {                
            }
            @Override
            public void mouseExited(MouseEvent me) {                
            }
        }); 
        selectionModel.addTreeSelectionListener(this);   
        if(usuario!=null){
            service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
            if(!p.isModificarPrivilegios()){
                arbolContenedor.setEditable(false);
                botonGuardar.setEnabled(false);
            }
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        arbolContenedor = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        campoTipoCuenta = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        campoNombreModificar = new javax.swing.JLabel();
        campoRutModificar = new javax.swing.JLabel();
        botonCancelar = new javax.swing.JButton();
        botonGuardar = new javax.swing.JButton();
        campoMensajeria = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        campoNombreActivo = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        campoRutActivo = new javax.swing.JLabel();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Privilegios");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Usuario");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Agregar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Modificar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Exportar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Buscar usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver privilegios de usuario");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Modificar privilegios de usuario");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Agenda");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema agenda");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Agregar cita");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Modificar cita");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar cita");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar cita");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Imprimir agenda diaria");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Buscar citas");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Listar citas no confirmadas");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Modificar citas no confirmadas");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver agenda de todos los profesionales");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Pagar cita");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Paciente");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema paciente");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Paciente");
        javax.swing.tree.DefaultMutableTreeNode treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar paciente");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar paciente");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha kinesiologia");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha kinesiología");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha podología");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha podología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha podología");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha psicología");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha psicología");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha pediatría");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha pediatría");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha siquiatría");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha siquiatría");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ficha medicina general");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar ficha medicina general");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Programas médicos");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema programas médicos");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("FONASA");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Imprimir programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar programa médico FONASA");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("DIPRECA");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Imprimir programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar programa médico DIPRECA");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("JEAFOSALE");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Imprimir programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar programa médico JEAFOSALE");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Derivaciones");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema derivaciones");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Derivaciones");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar derivación");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Orden de derivación");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar orden de derivación");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Profesional externo");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar profesional externo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar profesional externo");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Finanzas");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema finanzas");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Pagar con bono");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo pagos con bono");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar pagos con bono");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Cancelar pagos con bono");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar pagos con bono");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver pagos con bono");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Pagar con cheque");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo pagos con cheque");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar pagos con cheque");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Cancelar pagos con cheque");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar pagos con cheque");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver pagos con cheque");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Pagar en efectivo");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo pagos en efectivo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar pagos en efectivo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Cancelar pagos en efectivo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar pagos en efectivo");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver pagos en efectivo");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Llamadas telefónicas");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar llamadas telefónica");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Convenios");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver módulo convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Agregar convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Modificar convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Eliminar convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Restaurar convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Ver convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Exportar convenio");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Buscar convenio");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Bitacora");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver subsistema bitácora");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ver registro");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Buscar registro");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Filtrar registro");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        arbolContenedor.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(arbolContenedor);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de usuario"));

        jLabel1.setText("Tipo cuenta:");

        campoTipoCuenta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Profesional", "Secretaria", "Administrador" }));
        campoTipoCuenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoTipoCuentaActionPerformed(evt);
            }
        });

        jButton1.setText("Por defecto");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("Nombre:");

        jLabel3.setText("Rut:");

        campoNombreModificar.setText("jLabel4");

        campoRutModificar.setText("jLabel4");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoRutModificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoNombreModificar, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoTipoCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoNombreModificar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(campoRutModificar))
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jLabel1)
                    .addComponent(campoTipoCuenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        botonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png"))); // NOI18N
        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        campoMensajeria.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        campoMensajeria.setText("jLabel6");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Usuario activo"));

        jLabel4.setText("Nombre:");

        campoNombreActivo.setText("jLabel5");

        jLabel6.setText("Rut:");

        campoRutActivo.setText("jLabel5");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoNombreActivo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoRutActivo, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(campoNombreActivo)
                .addComponent(jLabel6)
                .addComponent(campoRutActivo))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoMensajeria, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(botonGuardar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botonCancelar))
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 489, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCancelar)
                    .addComponent(botonGuardar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoMensajeria)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * Closes the dialog
     */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        
        this.dispose();
    }//GEN-LAST:event_botonCancelarActionPerformed

    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed
        guardarPrivilegios();
    }//GEN-LAST:event_botonGuardarActionPerformed

    private void campoTipoCuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoTipoCuentaActionPerformed
        
    }//GEN-LAST:event_campoTipoCuentaActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if(((String)campoTipoCuenta.getSelectedItem()).equals("Profesional"))
            privilegiosProfesional(usuario.getTipoCuenta());
        if(((String)campoTipoCuenta.getSelectedItem()).equals("Administrador"))
            privilegiosAdministrador();
        if(((String)campoTipoCuenta.getSelectedItem()).equals("Secretaria"))
            privilegiosSecretaria();
    }//GEN-LAST:event_jButton1ActionPerformed
   
    public void addChildPaths(TreePath path, TreeModel model, List result){
        Object item = path.getLastPathComponent();
        int childCount = model.getChildCount(item);
        for(int i = 0; i<childCount; i++)
            result.add(path.pathByAddingChild(model.getChild(item, i)));
}

    public ArrayList getDescendants(TreePath paths[] , TreeModel model){
        ArrayList result = new ArrayList();
        Stack pending = new Stack();
        pending.addAll(Arrays.asList(paths));
        while(!pending.isEmpty()){
            TreePath path = (TreePath)pending.pop();
            addChildPaths(path, model, pending);
            result.add(path);
        }
        return result;
    }
     public void mouseClick(MouseEvent me){
        TreePath path = arbolContenedor.getPathForLocation(me.getX(), me.getY()); 
                if(path==null) 
                    return; 
                if(me.getX()>arbolContenedor.getPathBounds(path).x+hotspot) 
                    return; 

                boolean selected = selectionModel.isPathSelected(path, true); 
                selectionModel.removeTreeSelectionListener(this); 

                try{ 
                    if(selected) 
                        selectionModel.removeSelectionPath(path); 
                    else 
                        selectionModel.addSelectionPath(path); 
                } finally{ 
                    selectionModel.addTreeSelectionListener(this); 
                    arbolContenedor.treeDidChange(); 
        } 
    }
    public void cargarPrivilegiosUsuario(){
        System.out.println("cargo privilegios");
        service.Privilegios p = (service.Privilegios) cargarPrivilegios(usuario.getRut());
        ArrayList<TreePath> list = new ArrayList<TreePath>();
        //Usuario
        if(p.isVerSubsistemaUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,0"));                
        if(p.isAgregarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,1"));
        if(p.isModificarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,2"));    
        if(p.isEliminarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,3"));
        if(p.isRestaurarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,4"));
        if(p.isVerUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,5"));
        if(p.isExportarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,6"));
        if(p.isBuscarUsuario())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,7"));
        if(p.isVerPrivilegios())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,8"));
        if(p.isModificarPrivilegios())
            list.add(string2TreePath(arbolContenedor.getModel(), "0,9"));
        //Agenda
        if(p.isVerSubsistemaAgenda())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,0"));
        if(p.isAgregarCita())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,1"));
        if(p.isModificarCita())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,2"));
        if(p.isEliminarCita())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,3"));
        if(p.isRestaurarCita())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,4"));        
        if(p.isImprimirAgendaDiaria())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,5"));
        if(p.isBuscarCitas())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,6"));
        if(p.isListarcitasNoConfirmadas())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,7"));
        if(p.isModificarcitasNoConfirmadas())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,8"));
        if(p.isVerAgendaDeTodosLosProfesionales())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,9"));
        if(p.isPagarCita())
            list.add(string2TreePath(arbolContenedor.getModel(), "1,10"));
        //paciente
        if(p.isVerSubsistemaPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,0"));
        if(p.isVerModuloPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,0"));
        if(p.isAgregarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,1"));
        if(p.isModificarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,2"));
        if(p.isEliminarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,3"));
        if(p.isRestaurarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,4"));
        if(p.isVerPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,5"));
        if(p.isExportarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,6"));
        if(p.isBuscarPaciente())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,1,7"));
        //ficha kinesiologia
        if(p.isVerModuloFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,0"));
        if(p.isAgregarFichaKinesiologica())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,1"));
        if(p.isModificarFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,2"));
        if(p.isVerFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,3"));
        if(p.isExportarFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,4"));
        if(p.isEliminarFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,5"));
        if(p.isRestaurarFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,6"));
        if(p.isBuscarFichaKinesiologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2,7"));
        //ficha podologia
        if(p.isVerModuloFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,0"));
        if(p.isAgregarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,1"));
        if(p.isModificarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,2"));
        if(p.isVerFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,3"));
        if(p.isExportarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,4"));
        if(p.isEliminarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,5"));
        if(p.isRestaurarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,6"));
        if(p.isBuscarFichaPodologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3,7"));
        //ficha psicologia
        if(p.isVerModuloFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,0"));
        if(p.isAgregarFichaPsicoligia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,1"));
        if(p.isModificarFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,2"));
        if(p.isVerFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,3"));
        if(p.isExportarFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,4"));
        if(p.isEliminarFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,5"));
        if(p.isRestaurarFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,6"));
        if(p.isBuscarFichaPsicologia())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4,7"));
        //ficha pediatria
        if(p.isVerModuloFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,0"));
        if(p.isAgregarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,1"));
        if(p.isModificarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,2"));
        if(p.isVerFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,3"));
        if(p.isExportarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,4"));
        if(p.isEliminarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,5"));
        if(p.isRestaurarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,6"));
        if(p.isBuscarFichaPediatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5,7"));
        //ficha siquiatria
        if(p.isVerModuloFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,0"));
        if(p.isAgregarFichaSiquitria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,1"));
        if(p.isModificarFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,2"));
        if(p.isVerFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,3"));
        if(p.isExportarFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,4"));
        if(p.isEliminarFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,5"));
        if(p.isRestaurarFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,6"));
        if(p.isBuscarFichaSiquiatria())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6,7"));
        //ficha medicina general
        if(p.isVerModuloFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,0"));
        if(p.isAgregarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,1"));
        if(p.isModificarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,2"));
        if(p.isVerFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,3"));
        if(p.isExportarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,4"));
        if(p.isEliminarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,5"));
        if(p.isRestaurarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,6"));
        if(p.isBuscarFichaMedicinaGeneral())
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7,7"));
        //programas medicos
        if(p.isVerSubsistemaProgramasMedicos())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,0"));
        //programa medico FONASA
        if(p.isVerModuloProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,0"));
        if(p.isAgregarProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,1"));
        if(p.isModificarProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,2"));                
        if(p.isVerProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,3"));
        if(p.isImprimirProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,4"));
        if(p.isBuscarProgramaMedicoFonasa())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,1,5"));
        //programa medico DIPRECA
        if(p.isVerModuloProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,0"));
        if(p.isAgregarProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,1"));
        if(p.isModificarProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,2"));                
        if(p.isVerProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,3"));
        if(p.isImprimirProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,4"));
        if(p.isBuscarProgramaMedicoDipreca())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,2,5"));
        //programa medico JEAFOSALE
        if(p.isVerModuloProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,0"));
        if(p.isAgregarProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,1"));
        if(p.isModificarProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,2"));                
        if(p.isVerProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,3"));
        if(p.isImprimirProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,4"));
        if(p.isBuscarProgramaMedicoJeafosale())
            list.add(string2TreePath(arbolContenedor.getModel(), "3,3,5"));
        //subsistema derivacion
        if(p.isVerSubsistemaDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,0"));
        //derivacion
        if(p.isVerModuloDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,0"));
        if(p.isAgregarDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,1"));
        if(p.isModificarDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,2"));
        if(p.isEliminarDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,3"));
        if(p.isRestaurarDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,4"));
        if(p.isVerDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,5"));
        if(p.isExportarDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,6"));
        if(p.isBuscarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,1,7"));
        //orden de derivacion
        if(p.isVerModuloOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,0"));
        if(p.isAgregarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,1"));
        if(p.isModificarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,2"));
        if(p.isEliminarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,3"));
        if(p.isRestaurarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,4"));
        if(p.isVerOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,5"));
        if(p.isExportarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,6"));
        if(p.isBuscarOrdenDerivacion())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,2,7"));
        //profesional externo
        if(p.isVerModuloProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,0"));
        if(p.isAgregarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,1"));
        if(p.isModificarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,2"));
        if(p.isEliminarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,3"));
        if(p.isRestaurarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,4"));
        if(p.isVerProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,5"));
        if(p.isExportarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,6"));
        if(p.isBuscarProfesionalExterno())
            list.add(string2TreePath(arbolContenedor.getModel(), "4,3,7"));
        //finanzas
        if(p.isVerModuloPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,0"));
        //pagar con bono
        if(p.isVerModuloPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,1,0"));
        if(p.isModificarPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,1,1"));
        if(p.isCancelarPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,1,2"));
        if(p.isBuscarPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,1,3"));
        if(p.isVerPagosConBono())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,1,4"));
        //pagar con cheque
        if(p.isVerModuloPagosConCheque())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,2,0"));
        if(p.isModificarPagosConCheque())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,2,1"));
        if(p.isCancelarPagosConCheque())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,2,2"));
        if(p.isBuscarPagosConCheque())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,2,3"));
        if(p.isVerPagosConCheque())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,2,4"));
        //pagar con efectivo
        if(p.isVerModuloPagoEnEfectivo())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,3,0"));
        if(p.isModificarPagosEnEfectivo())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,3,1"));
        if(p.isCancelarPagosEnEfectivo())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,3,2"));
        if(p.isBuscarPagosEnEfectivo())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,3,3"));
        if(p.isVerPagosEnEfectivo())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,3,4"));
        //llamada telefonica
        if(p.isVerModuloLlamadaTelefonica())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,0"));
        if(p.isAgregarLlamadaTelefonica())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,1"));
        if(p.isModificarLlamadaTelefonica())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,2"));        
        if(p.isExportarLlamadaTelefonica())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,3"));
        if(p.isVerLlamadaTelefonica())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,4"));
        if(p.isBuscarLlamadasTelefonicas())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,4,5"));
        //convenios
        if(p.isVerModuloConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,0"));
        if(p.isAgregarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,1"));
        if(p.isModificarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,2"));
        if(p.isEliminarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,3"));
        if(p.isRestaurarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,4"));
        if(p.isVerConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,5"));
        if(p.isExportarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,6"));
        if(p.isBuscarConvenio())
            list.add(string2TreePath(arbolContenedor.getModel(), "5,5,7"));
        //bitacora
        if(p.isVerSubsistemaBitacora())
            list.add(string2TreePath(arbolContenedor.getModel(), "6,0"));
        if(p.isVerRegistro())
            list.add(string2TreePath(arbolContenedor.getModel(), "6,1"));
        if(p.isBuscarRegistro())
            list.add(string2TreePath(arbolContenedor.getModel(), "6,2"));
        if(p.isFiltrarRegistro())
            list.add(string2TreePath(arbolContenedor.getModel(), "6,3"));
                
        
        TreePath []paths = new TreePath[list.size()];
        for(int i = 0 ; i<list.size() ; i++){
            paths[i]=list.get(i);
        }
        getSelectionModel().setSelectionPaths(paths);
    }
    public TreePath string2TreePath(TreeModel model, String str){ 
        StringTokenizer stok = new StringTokenizer(str, ","); 
        Object path[] = new Object[stok.countTokens()+1]; 
        path[0] = model.getRoot(); 

        for(int i = 1; stok.hasMoreTokens(); i++){ 
            int index = Integer.parseInt(stok.nextToken()); 
            path[i] = model.getChild(path[i-1], index); 
        } 
        return new TreePath(path); 
    } 

    public String treePath2String(TreeModel model, TreePath treePath){ 
        Object[] path = treePath.getPath(); 
        StringBuffer buf = new StringBuffer(); 
        for(int i=1; i<path.length; i++){ 
            if(buf.length()!=0) 
                buf.append(','); 
            buf.append(model.getIndexOfChild(path[i-1], path[i])); 
        } 
        return buf.toString(); 
    } 
    public void privilegiosProfesional(String tipo) {
        service.Privilegios p = new service.Privilegios();
        ArrayList<TreePath> list = new ArrayList<TreePath>();
        //agenda
        list.add(string2TreePath(arbolContenedor.getModel(), "1,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,2"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,5"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,6"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1,8"));        
        //paciente
        list.add(string2TreePath(arbolContenedor.getModel(), "2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,2"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,5"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,6"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1,7"));
        //ficha
        if(tipo.equals("Medicina general"))
            list.add(string2TreePath(arbolContenedor.getModel(), "2,7"));        
        if(tipo.equals("Kinesiología"))
            list.add(string2TreePath(arbolContenedor.getModel(), "2,2"));        
        if(tipo.equals("Podología"))
            list.add(string2TreePath(arbolContenedor.getModel(), "2,3"));        
        if(tipo.equals("Psicología"))            
            list.add(string2TreePath(arbolContenedor.getModel(), "2,4"));
        if(tipo.equals("Psiquiatría"))
            list.add(string2TreePath(arbolContenedor.getModel(), "2,6"));        
        if(tipo.equals("Pediatría"))
            list.add(string2TreePath(arbolContenedor.getModel(), "2,5"));
        //programas medicos
        list.add(string2TreePath(arbolContenedor.getModel(), "3"));
        //derivaciones
        list.add(string2TreePath(arbolContenedor.getModel(), "4"));
        //finanzas
        list.add(string2TreePath(arbolContenedor.getModel(), "5,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,1,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,1,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,1,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,2,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,2,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,3,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,3,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5,3,4"));        
        
        TreePath []paths = new TreePath[list.size()];
        for(int i = 0 ; i<list.size() ; i++){
            paths[i]=list.get(i);
        }
        getSelectionModel().setSelectionPaths(paths);        
    }
    public void privilegiosSecretaria() {
        ArrayList<TreePath> list = new ArrayList<TreePath>();
        
        list.add(string2TreePath(arbolContenedor.getModel(), "1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5"));                
        
        TreePath []paths = new TreePath[list.size()];
        for(int i = 0 ; i<list.size() ; i++){
            paths[i]=list.get(i);
        }
        getSelectionModel().setSelectionPaths(paths);
    }
    public void privilegiosAdministrador() {
        System.out.println("Privilegios de administrador");
        ArrayList<TreePath> list = new ArrayList<TreePath>();
        list.add(string2TreePath(arbolContenedor.getModel(), "0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,1"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,2,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,3,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,4,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,5,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,6,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,0"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "2,7,7"));
        list.add(string2TreePath(arbolContenedor.getModel(), "3"));
        list.add(string2TreePath(arbolContenedor.getModel(), "4"));
        list.add(string2TreePath(arbolContenedor.getModel(), "5"));
        list.add(string2TreePath(arbolContenedor.getModel(), "6"));
        
        TreePath []paths = new TreePath[list.size()];
        for(int i = 0 ; i<list.size() ; i++){
            paths[i]=list.get(i);
        }
        getSelectionModel().setSelectionPaths(paths);
    }

    
    public void setUsuario(service.Usuario u){
        this.usuario = u;
    }
       
    public CheckTreeSelectionModel getSelectionModel(){ 
        return selectionModel; 
    } 
    @Override
    public void valueChanged(TreeSelectionEvent tse) {
        arbolContenedor.treeDidChange(); 
    }
    public void normalizarMensajeria(){
        campoMensajeria.setText("Área de mensajería");
        campoMensajeria.setForeground(Color.blue);
    }
    public void cambiarEtiquetaMensajeria(String mensaje, Color color){
        campoMensajeria.setText(mensaje);
        campoMensajeria.setForeground(color);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTree arbolContenedor;
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JLabel campoMensajeria;
    private javax.swing.JLabel campoNombreActivo;
    private javax.swing.JLabel campoNombreModificar;
    private javax.swing.JLabel campoRutActivo;
    private javax.swing.JLabel campoRutModificar;
    private javax.swing.JComboBox campoTipoCuenta;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public void guardarPrivilegios() {
        ArrayList<TreePath> a = getDescendants(getSelectionModel().getSelectionPaths(), arbolContenedor.getModel());
        service.Privilegios p = new service.Privilegios();
        p.setRutUsuario(usuario.getRut());
        for(int i = 0 ; i<a.size() ; i++){
            for(int j = 0 ; j<a.get(i).getPathCount(); j++){
                   //usuario
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema usuario"))
                        p.setVerSubsistemaUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar usuario"))
                        p.setAgregarUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar usuario"))
                        p.setModificarUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar usuario"))
                        p.setEliminarUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar usuario"))
                        p.setRestaurarUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver usuario"))
                        p.setVerUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar usuario"))
                        p.setExportarUsuario(true);                    
                    if(a.get(i).getPath()[j].toString().equals("Buscar usuario"))
                        p.setBuscarUsuario(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver privilegios de usuario"))
                        p.setVerPrivilegios(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar privilegios de usuario"))
                        p.setModificarPrivilegios(true);
                    //agenda
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema agenda"))
                        p.setVerSubsistemaAgenda(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar cita"))
                        p.setAgregarCita(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar cita"))
                        p.setModificarCita(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar cita"))
                        p.setEliminarCita(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar cita"))
                        p.setRestaurarCita(true);                    
                    if(a.get(i).getPath()[j].toString().equals("Imprimir agenda diaria"))
                        p.setImprimirAgendaDiaria(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar citas"))
                        p.setBuscarCitas(true);
                    if(a.get(i).getPath()[j].toString().equals("Listar citas no confirmadas"))
                        p.setListarcitasNoConfirmadas(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar citas no confirmadas"))
                        p.setModificarcitasNoConfirmadas(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver agenda de todos los profesionales"))
                        p.setVerAgendaDeTodosLosProfesionales(true);
                    if(a.get(i).getPath()[j].toString().equals("Pagar cita"))
                        p.setPagarCita(true);
                    //Paciente
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema paciente"))
                        p.setVerSubsistemaPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo paciente"))
                        p.setVerModuloPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar paciente"))
                        p.setAgregarPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar paciente"))
                        p.setModificarPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar paciente"))
                        p.setEliminarPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar paciente"))
                        p.setRestaurarPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver paciente"))
                        p.setVerPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar paciente"))
                        p.setExportarPaciente(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar paciente"))
                        p.setBuscarPaciente(true);
                    //ficha kinesiologica
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha kinesiología"))
                        p.setVerModuloFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha kinesiología"))
                        p.setAgregarFichaKinesiologica(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha kinesiología"))
                        p.setModificarFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha kinesiología"))
                        p.setVerFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha kinesiología"))
                        p.setExportarFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha kinesiología"))
                        p.setEliminarFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha kinesiología"))
                        p.setRestaurarFichaKinesiologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha kinesiología"))
                        p.setBuscarFichaKinesiologia(true);
                    //ficha podologia
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha podología"))
                        p.setVerModuloFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha podología"))
                        p.setAgregarFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha podología"))
                        p.setModificarFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha podología"))
                        p.setVerFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha podología"))
                        p.setExportarFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha podología"))
                        p.setEliminarFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha podología"))
                        p.setRestaurarFichaPodologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha podología"))
                        p.setBuscarFichaPodologia(true);
                    //ficha psicología
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha psicología"))
                        p.setVerModuloFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha psicología"))
                        p.setAgregarFichaPsicoligia(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha psicología"))
                        p.setModificarFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha psicología"))
                        p.setVerFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha psicología"))
                        p.setExportarFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha psicología"))
                        p.setEliminarFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha psicología"))
                        p.setRestaurarFichaPsicologia(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha psicología"))
                        p.setBuscarFichaPsicologia(true);
                    //ficha pediatría
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha pediatría"))
                        p.setVerModuloFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha pediatría"))
                        p.setAgregarFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha pediatría"))
                        p.setModificarFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha pediatría"))
                        p.setVerFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha pediatría"))
                        p.setExportarFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha pediatría"))
                        p.setEliminarFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha pediatría"))
                        p.setRestaurarFichaPediatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha pediatría"))
                        p.setBuscarFichaPediatria(true);
                    //ficha siquiatría
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha siquiatría"))
                        p.setVerModuloFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha siquiatría"))
                        p.setAgregarFichaSiquitria(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha siquiatría"))
                        p.setModificarFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha siquiatría"))
                        p.setVerFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha siquiatría"))
                        p.setExportarFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha siquiatría"))
                        p.setEliminarFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha siquiatría"))
                        p.setRestaurarFichaSiquiatria(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha siquiatría"))
                        p.setBuscarFichaSiquiatria(true);
                    //ficha medicina general
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo ficha medicina general"))
                        p.setVerModuloFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar ficha medicina general"))
                        p.setAgregarFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar ficha medicina general"))
                        p.setModificarFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver ficha medicina general"))
                        p.setVerFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar ficha medicina general"))
                        p.setExportarFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar ficha medicina general"))
                        p.setEliminarFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar ficha medicina general"))
                        p.setRestaurarFichaMedicinaGeneral(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar ficha medicina general"))
                        p.setBuscarFichaMedicinaGeneral(true);
                    //programa medico FONASA
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema programas médicos"))
                        p.setVerSubsistemaProgramasMedicos(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo programa médico FONASA"))
                        p.setVerModuloProgramaMedicoFonasa(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar programa médico FONASA"))
                        p.setAgregarProgramaMedicoFonasa(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar programa médico FONASA"))
                        p.setModificarProgramaMedicoFonasa(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver programa médico FONASA"))
                        p.setVerProgramaMedicoFonasa(true);
                    if(a.get(i).getPath()[j].toString().equals("Imprimir programa médico FONASA"))
                        p.setImprimirProgramaMedicoFonasa(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar programa médico FONASA"))
                        p.setBuscarProgramaMedicoFonasa(true);
                    //programa medico DIPRECA
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo programa médico DIPRECA"))
                        p.setVerModuloProgramaMedicoDipreca(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar programa médico DIPRECA"))
                        p.setAgregarProgramaMedicoDipreca(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar programa médico DIPRECA"))
                        p.setModificarProgramaMedicoDipreca(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver programa médico DIPRECA"))
                        p.setVerProgramaMedicoDipreca(true);
                    if(a.get(i).getPath()[j].toString().equals("Imprimir programa médico DIPRECA"))
                        p.setImprimirProgramaMedicoDipreca(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar programa médico DIPRECA"))
                        p.setBuscarProgramaMedicoDipreca(true);
                    //programa medico JEAFOSALE
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo programa médico JEAFOSALE"))
                        p.setVerModuloProgramaMedicoJeafosale(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar programa médico JEAFOSALE"))
                        p.setAgregarProgramaMedicoJeafosale(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar programa médico JEAFOSALE"))
                        p.setModificarProgramaMedicoJeafosale(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver programa médico JEAFOSALE"))
                        p.setVerProgramaMedicoJeafosale(true);
                    if(a.get(i).getPath()[j].toString().equals("Imprimir programa médico JEAFOSALE"))
                        p.setImprimirProgramaMedicoJeafosale(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar programa médico JEAFOSALE"))
                        p.setBuscarProgramaMedicoJeafosale(true);
                    //derivacion
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema derivaciones"))
                        p.setVerSubsistemaDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo derivación"))
                        p.setVerModuloDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar derivación"))
                        p.setAgregarDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar derivación"))
                        p.setModificarDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar derivación"))
                        p.setEliminarDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar derivación"))
                        p.setRestaurarDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver derivación"))
                        p.setVerDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar derivación"))
                        p.setExportarDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar derivación"))
                        p.setBuscarDerivacion(true);  
                    //Orden de derivacion
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo orden de derivación"))
                        p.setVerModuloOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar orden de derivación"))
                        p.setAgregarOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar orden de derivación"))
                        p.setModificarOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar orden de derivación"))
                        p.setEliminarOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar orden de derivación"))
                        p.setRestaurarOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver orden de derivación"))
                        p.setVerOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar orden de derivación"))
                        p.setExportarOrdenDerivacion(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar orden de derivación"))
                        p.setBuscarOrdenDerivacion(true);                 
                    //profesional externo
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo profesional externo"))
                        p.setVerModuloProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar profesional externo"))
                        p.setAgregarProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar profesional externo"))
                        p.setModificarProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar profesional externo"))
                        p.setEliminarProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar profesional externo"))
                        p.setRestaurarProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver profesional externo"))
                        p.setVerProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar profesional externo"))
                        p.setExportarProfesionalExterno(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar profesional externo"))
                        p.setBuscarProfesionalExterno(true);                 
                    //pago con bono
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema finanzas"))
                        p.setVerSubsistemaFinanzas(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo pagos con bono"))
                        p.setVerModuloPagosConBono(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar pagos con bono"))
                        p.setModificarPagosConBono(true);
                    if(a.get(i).getPath()[j].toString().equals("Cancelar pagos con bono"))
                        p.setCancelarPagosConBono(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar pagos con bono"))
                        p.setBuscarPagosConBono(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver pagos con bono"))
                        p.setVerPagosConBono(true);
                    //pago con cheque
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo pagos con cheque"))
                        p.setVerModuloPagosConCheque(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar pagos con cheque"))
                        p.setModificarPagosConCheque(true);
                    if(a.get(i).getPath()[j].toString().equals("Cancelar pagos con cheque"))
                        p.setCancelarPagosConCheque(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar pagos con cheque"))
                        p.setBuscarPagosConCheque(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver pagos con cheque"))
                        p.setVerPagosConCheque(true);
                    //pago en efectivo
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo pagos en efectivo"))
                        p.setVerModuloPagoEnEfectivo(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar pagos en efectivo"))
                        p.setModificarPagosEnEfectivo(true);
                    if(a.get(i).getPath()[j].toString().equals("Cancelar pagos en efectivo"))
                        p.setCancelarPagosEnEfectivo(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar pagos en efectivo"))
                        p.setBuscarPagosEnEfectivo(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver pagos en efectivo"))
                        p.setVerPagosEnEfectivo(true);
                    //llamadas telefonicas
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo llamadas telefónica"))
                        p.setVerModuloLlamadaTelefonica(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar llamadas telefónica"))
                        p.setAgregarLlamadaTelefonica(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar llamadas telefónica"))
                        p.setModificarLlamadaTelefonica(true);                    
                    if(a.get(i).getPath()[j].toString().equals("Exportar llamadas telefónica"))
                        p.setExportarLlamadaTelefonica(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver llamadas telefónica"))
                        p.setVerLlamadaTelefonica(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar llamadas telefónica"))
                        p.setBuscarLlamadasTelefonicas(true);
                    //convenios
                    if(a.get(i).getPath()[j].toString().equals("Ver módulo convenio"))
                        p.setVerModuloConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Agregar convenio"))
                        p.setAgregarConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Modificar convenio"))
                        p.setModificarConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Eliminar convenio"))
                        p.setEliminarConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Restaurar convenio"))
                        p.setRestaurarConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver convenio"))
                        p.setVerConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Exportar convenio"))
                        p.setExportarConvenio(true);
                    if(a.get(i).getPath()[j].toString().equals("Buscar convenio"))
                        p.setBuscarConvenio(true);
                    //bitacora
                    if(a.get(i).getPath()[j].toString().equals("Ver subsistema bitácora"))
                        p.setVerSubsistemaBitacora(true);
                    if(a.get(i).getPath()[j].toString().equals("Ver registro")) 
                                p.setVerRegistro(true);        
                    if(a.get(i).getPath()[j].toString().equals("Buscar registro")) 
                                p.setBuscarRegistro(true);            
                    if(a.get(i).getPath()[j].toString().equals("Filtrar registro")) 
                                p.setFiltrarRegistro(true);    
            }
        }
        modificarPrivilegios(p);
        usuario.setTipoCuenta((String)campoTipoCuenta.getSelectedItem());
        modificarUsuario(usuario);
        this.dispose();
    }
    public class CheckTreeSelectionModel extends DefaultTreeSelectionModel{ 
    private TreeModel model; 
 
    public CheckTreeSelectionModel(TreeModel model){ 
        this.model = model; 
        setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); 
    } 
    // tests whether there is any unselected node in the subtree of given path 
    public boolean isPartiallySelected(TreePath path){ 
        if(isPathSelected(path, true)) 
            return false; 
        TreePath[] selectionPaths = getSelectionPaths(); 
        if(selectionPaths==null) 
            return false; 
        for(int j = 0; j<selectionPaths.length; j++){ 
            if(isDescendant(selectionPaths[j], path)) 
                return true; 
        } 
        return false; 
    } 
 
    // tells whether given path is selected. 
    // if dig is true, then a path is assumed to be selected, if 
    // one of its ancestor is selected. 
    public boolean isPathSelected(TreePath path, boolean dig){ 
        if(!dig) 
            return super.isPathSelected(path); 
        while(path!=null && !super.isPathSelected(path)) 
            path = path.getParentPath(); 
        return path!=null; 
    } 
 
    // is path1 descendant of path2 
    private boolean isDescendant(TreePath path1, TreePath path2){ 
        Object obj1[] = path1.getPath(); 
        Object obj2[] = path2.getPath(); 
        for(int i = 0; i<obj2.length; i++){ 
            if(obj1[i]!=obj2[i]) 
                return false; 
        } 
        return true; 
    } 
 
    public void setSelectionPaths(TreePath[] pPaths){ 
        clearSelection(); 
        for(int i=0; i<pPaths.length; i++) 
            addSelectionPath(pPaths[i]); 
}
 
    public void addSelectionPaths(TreePath[] paths){ 
        // unselect all descendants of paths[] 
        for(int i = 0; i<paths.length; i++){ 
            TreePath path = paths[i]; 
            TreePath[] selectionPaths = getSelectionPaths(); 
            if(selectionPaths==null) 
                break; 
            ArrayList toBeRemoved = new ArrayList(); 
            for(int j = 0; j<selectionPaths.length; j++){ 
                if(isDescendant(selectionPaths[j], path)) 
                    toBeRemoved.add(selectionPaths[j]); 
            } 
            super.removeSelectionPaths((TreePath[])toBeRemoved.toArray(new TreePath[0])); 
        } 
 
        // if all siblings are selected then unselect them and select parent recursively 
        // otherwize just select that path. 
        for(int i = 0; i<paths.length; i++){ 
            TreePath path = paths[i]; 
            TreePath temp = null; 
            while(areSiblingsSelected(path)){ 
                temp = path; 
                if(path.getParentPath()==null) 
                    break; 
                path = path.getParentPath(); 
            } 
            if(temp!=null){ 
                if(temp.getParentPath()!=null) 
                    addSelectionPath(temp.getParentPath()); 
                else{ 
                    if(!isSelectionEmpty()) 
                        removeSelectionPaths(getSelectionPaths()); 
                    super.addSelectionPaths(new TreePath[]{temp}); 
                } 
            }else 
                super.addSelectionPaths(new TreePath[]{ path}); 
        } 
    } 
 
    // tells whether all siblings of given path are selected. 
    private boolean areSiblingsSelected(TreePath path){ 
        TreePath parent = path.getParentPath(); 
        if(parent==null) 
            return true; 
        Object node = path.getLastPathComponent(); 
        Object parentNode = parent.getLastPathComponent(); 
 
        int childCount = model.getChildCount(parentNode); 
        for(int i = 0; i<childCount; i++){ 
            Object childNode = model.getChild(parentNode, i); 
            if(childNode==node) 
                continue; 
            if(!isPathSelected(parent.pathByAddingChild(childNode))) 
                return false; 
        } 
        return true; 
    } 
 
    public void removeSelectionPaths(TreePath[] paths){ 
        for(int i = 0; i<paths.length; i++){ 
            TreePath path = paths[i]; 
            if(path.getPathCount()==1) 
                super.removeSelectionPaths(new TreePath[]{ path}); 
            else 
                toggleRemoveSelection(path); 
        } 
    } 
 
    // if any ancestor node of given path is selected then unselect it 
    //  and selection all its descendants except given path and descendants. 
    // otherwise just unselect the given path 
    private void toggleRemoveSelection(TreePath path){ 
        Stack stack = new Stack(); 
        TreePath parent = path.getParentPath(); 
        while(parent!=null && !isPathSelected(parent)){ 
            stack.push(parent); 
            parent = parent.getParentPath(); 
        } 
        if(parent!=null) 
            stack.push(parent); 
        else{ 
            super.removeSelectionPaths(new TreePath[]{path}); 
            return; 
        } 
 
        while(!stack.isEmpty()){ 
            TreePath temp = (TreePath)stack.pop(); 
            TreePath peekPath = stack.isEmpty() ? path : (TreePath)stack.peek(); 
            Object node = temp.getLastPathComponent(); 
            Object peekNode = peekPath.getLastPathComponent(); 
            int childCount = model.getChildCount(node); 
            for(int i = 0; i<childCount; i++){ 
                Object childNode = model.getChild(node, i); 
                if(childNode!=peekNode) 
                    super.addSelectionPaths(new TreePath[]{temp.pathByAddingChild(childNode)}); 
            } 
        } 
        super.removeSelectionPaths(new TreePath[]{parent}); 
    } 
    }
    public class CheckTreeCellRenderer extends JPanel implements TreeCellRenderer{ 
    private CheckTreeSelectionModel selectionModel; 
    private TreeCellRenderer delegate; 
    private TristateCheckBox checkBox = new TristateCheckBox(); 
 
    public CheckTreeCellRenderer(TreeCellRenderer delegate, CheckTreeSelectionModel selectionModel){ 
        this.delegate = delegate; 
        this.selectionModel = selectionModel; 
        setLayout(new BorderLayout()); 
        setOpaque(false); 
        checkBox.setOpaque(false); 
    } 
 
 
        @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus){ 
        Component renderer = delegate.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); 
 
        TreePath path = tree.getPathForRow(row); 
        if(path!=null){ 
            if(selectionModel.isPathSelected(path, true)) 
                checkBox.setState(Boolean.TRUE); 
            else 
                checkBox.setState(selectionModel.isPartiallySelected(path) ? null : Boolean.FALSE); 
        } 
        removeAll(); 
        add(checkBox, BorderLayout.WEST); 
        add(renderer, BorderLayout.CENTER); 
        return this; 
    } 
}

    private static boolean modificarPrivilegios(service.Privilegios privilegios) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.modificarPrivilegios(privilegios);
    }

    private static Object cargarPrivilegios(java.lang.String rut) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.cargarPrivilegios(rut);
    }    

    private static boolean modificarUsuario(service.Usuario usuario) {
        service.UsuarioWSService service = new service.UsuarioWSService();
        service.UsuarioWS port = service.getUsuarioWSPort();
        return port.modificarUsuario(usuario);
    }
}
/**
 * Maintenance tip - There were some tricks to getting this code
 * working:
 *
 * 1. You have to overwite addMouseListener() to do nothing
 * 2. You have to add a mouse event on mousePressed by calling
 * super.addMouseListener()
 * 3. You have to replace the UIActionMap for the keyboard event
 * "pressed" with your own one.
 * 4. You have to remove the UIActionMap for the keyboard event
 * "released".
 * 5. You have to grab focus when the next state is entered,
 * otherwise clicking on the component won't get the focus.
 * 6. You have to make a TristateDecorator as a button model that
 * wraps the original button model and does state management.
 */

    class TristateCheckBox extends JCheckBox{
    private final TristateCheckBox.TristateDecorator model;

    public TristateCheckBox(String text, Icon icon, Boolean initial){
        super(text, icon);
        // Add a listener for when the mouse is pressed
        super.addMouseListener(new MouseAdapter(){
            public void mousePressed(MouseEvent e){
                grabFocus();
                model.nextState();
            }
        });
        // Reset the keyboard action map
        ActionMap map = new ActionMapUIResource();
        map.put("pressed", new AbstractAction(){      //NOI18N
            public void actionPerformed(ActionEvent e){
                grabFocus();
                model.nextState();
            }
        });
        map.put("released", null);                     //NOI18N
        SwingUtilities.replaceUIActionMap(this, map);
        // set the model to the adapted model
        model = new TristateCheckBox.TristateDecorator(getModel());
        setModel(model);
        setState(initial);
    }

    public TristateCheckBox(String text, Boolean initial){
        this(text, null, initial);
    }

    public TristateCheckBox(String text){
        this(text, null);
    }

    public TristateCheckBox(){
        this(null);
    }

    /** No one may add mouse listeners, not even Swing! */
    public void addMouseListener(MouseListener l){}

    /**
     * Set the new state to either SELECTED, NOT_SELECTED or
     * DONT_CARE.  If state == null, it is treated as DONT_CARE.
     */
    public void setState(Boolean state){
        model.setState(state);
    }

    /** Return the current state, which is determined by the
     * selection status of the model. */
    public Boolean getState(){
        return model.getState();
    }

    /**
     * Exactly which Design Pattern is this?  Is it an Adapter,
     * a Proxy or a Decorator?  In this case, my vote lies with the
     * Decorator, because we are extending functionality and
     * "decorating" the original model with a more powerful model.
     */
    private class TristateDecorator implements ButtonModel{
        private final ButtonModel other;
        private TristateDecorator(ButtonModel other){
            this.other = other;
        }

        private void setState(Boolean state){
            if(state==Boolean.FALSE){
                other.setArmed(false);
                setPressed(false);
                setSelected(false);
            } else if(state==Boolean.TRUE){
                other.setArmed(false);
                setPressed(false);
                setSelected(true);
            } else{
                other.setArmed(true);
                setPressed(true);
                setSelected(true);
            }
        }

        /**
         * The current state is embedded in the selection / armed
         * state of the model.
         *
         * We return the SELECTED state when the checkbox is selected
         * but not armed, DONT_CARE state when the checkbox is
         * selected and armed (grey) and NOT_SELECTED when the
         * checkbox is deselected.
         */
        private Boolean getState(){
            if(isSelected() && !isArmed()){
                // normal black tick
                return Boolean.TRUE;
            } else if(isSelected() && isArmed()){
                // don't care grey tick
                return null;
            } else{
                // normal deselected
                return Boolean.FALSE;
            }
        }


        /** We rotate between NOT_SELECTED, SELECTED and DONT_CARE.*/
        private void nextState(){
            Boolean current = getState();
            if(current == Boolean.FALSE){
                setState(Boolean.TRUE);
            } else if(current == Boolean.TRUE){
                setState(null);
            } else if(current == null){
                setState(Boolean.FALSE);
            }
        }


        /** Filter: No one may change the armed status except us. */
        public void setArmed(boolean b){
        }

        public boolean isFocusTraversable() {
            return isEnabled();
        }

        /** We disable focusing on the component when it is not
         * enabled. */
        public void setEnabled(boolean b){
//            setFocusable(b);
            other.setEnabled(b);
        }


        /** All these methods simply delegate to the "other" model
         * that is being decorated. */
        public boolean isArmed(){return other.isArmed();
        }

        public boolean isSelected(){return other.isSelected();
        }

        public boolean isEnabled(){return other.isEnabled();
        }

        public boolean isPressed(){return other.isPressed();
        }

        public boolean isRollover(){return other.isRollover();
        }

        public void setSelected(boolean b){other.setSelected(b);
        }

        public void setPressed(boolean b){other.setPressed(b);
        }

        public void setRollover(boolean b){other.setRollover(b);
        }

        public void setMnemonic(int key){other.setMnemonic(key);
        }

        public int getMnemonic(){return other.getMnemonic();
        }

        public void setActionCommand(String s){
            other.setActionCommand(s);
        }

        public String getActionCommand(){
            return other.getActionCommand();
        }

        public void setGroup(ButtonGroup group){
            other.setGroup(group);
        }

        public void addActionListener(ActionListener l){
            other.addActionListener(l);
        }

        public void removeActionListener(ActionListener l){
            other.removeActionListener(l);
        }

        public void addItemListener(ItemListener l){
            other.addItemListener(l);
        }

        public void removeItemListener(ItemListener l){
            other.removeItemListener(l);
        }

        public void addChangeListener(ChangeListener l){
            other.addChangeListener(l);
        }

        public void removeChangeListener(ChangeListener l){
            other.removeChangeListener(l);
        }

        public Object[] getSelectedObjects(){
            return other.getSelectedObjects();
        }
    }


    
}